<template>
	<!-- 我的需求 -->
	<view>
		<!-- tabs -->
		<u-tabs :list="tabList" :is-scroll="true" :current="current" @change="change"></u-tabs>
		<!-- 列表 -->
		<view>
			<u-card v-for="(item,index) in xuqiuList" :key='index' :title="item.title" :sub-title="item.createtime" >
					<view class="card_view" slot="body">
						<view><text class="titlee">土地面积</text>：{{item.mianji}}</view>
						<view><text class="titlee">单价</text>：{{item.price}}</view>
						<view><text class="titlee">共计费用</text>：{{item.money}}</view>
						<view><text class="titlee">定金</text>：{{item.ding_money}}</view>
						<view v-if="item.ding_image"><text class="titlee">定金凭证</text>：<image :src="item.ding_image" style="width:100rpx;height:100rpx;"></image></view>
						<view><text class="titlee">尾款</text>：{{item.wei_money}}</view>
						<view v-if="item.wei_image"><text class="titlee">尾款凭证</text>：<image :src="item.wei_image" style="width:100rpx;height:100rpx;"></image></view>
						<view><text class="titlee">耕作要求</text>：{{item.yaoqiu}}</view>
						<view v-if="item.njs_name"><text class="titlee">农机手姓名</text>：{{item.njs_name}}</view>
						<view v-if="item.njs_phone" @click="call(item.njs_phone)"><text class="titlee">农机手电话</text>：{{item.njs_phone}}<u-icon name="phone-fill" color="#4bbb89" style="margin-left:10rpx;"></u-icon></view>
						<view><text class="titlee">地址</text>：{{item.address}}</view>
						<view v-if="item.status==1"><text class="titlee">状态</text>：{{item.work_status_text1}}</view>
					</view>
					<view class="" slot="foot" v-if="item.work_status==0.1">
						<button class="btn1" @click="yanshou(item.id,1)" style="display: inline-block;margin: 20rpx 0;">确认农机手接单</button>
						<button class="btn1" @click="yanshou(item.id,0)" style="background-color: red;display: inline-block;margin: 20rpx 0;margin-left: 20rpx;">拒绝农机手接单</button>
					</view>
					<view class="" slot="foot" v-if="item.work_status==1">
						<button class="btn1" @click="goUrl('/pages/index/payDing?id='+item.id)">确认已支付定金</button>
					</view>
					<view class="" slot="foot" v-if="item.work_status==4" style="display: flex;justify-content: space-evenly;">
						<button class="btn1" style="display: inline-block;margin: 20rpx 0;" @click="yanshou(item.id,5)">验收通过</button>
						<button class="btn1" style="background-color: red;display: inline-block;margin: 20rpx 0;" @click="yanshou(item.id,-5)">验收不通过</button>
					</view>
					<view class="" slot="foot" v-if="item.work_status==6">
						<button class="btn1" @click="goUrl('/pages/index/payWei?id='+item.id)">确认已支付尾款</button>
					</view>
				</u-card>
		</view>
		<button class="btn" @click="goUrl('/pages/index/fabu')">发布</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				tabList: [{
					name: '审核中'
				}, {
					name: '已审核'
				}, {
					name: '已驳回',
					// cate_count: 5
				}],
				current: 0,
				page:1,
				limit:10,
				total:0,
				xuqiuList:[]
			}
		},
		onShow() {
			this.xuqiuList = [];
			this.page =1;
			this.getXuqiuList(1)
		},
		onReachBottom() {
			if(this.xuqiuList.length<this.total){
				this.getXuqiuList()
			}
		},
		methods: {
			//切换标签
			change(index) {
				this.current = index;
				this.xuqiuList = [];
				this.page =1;
				this.getXuqiuList(1);
			},
			getXuqiuList(num){
				var _this = this;
				_this.$http('apply.myXuqiuList',{
					page:num?num:_this.page,
					limit:_this.limit,
					index:_this.current
				}).then(res=>{
					if(res.code == 0){
						uni.showModal({
							title:'提示',
							content:res.msg,
							success(ret){
								if(ret.confirm){
									// if(res.msg == '请前去申请成为农户'){
									// 	uni.navigateTo({
									// 		url:'/pages/index/nh_apply'
									// 	})
									// }else 
									if(res.msg == '您的申请正在审核中'){
										uni.navigateBack()
									}else{
										uni.navigateTo({
											url:'/pages/index/nh_apply'
										})
									}
								}
								if(ret.cancel){
									uni.redirectTo({
										url:"/pages/index/dating"
									})
								}
							}
						})
					}else{
						_this.xuqiuList = _this.xuqiuList.concat(res.data.list);
						_this.total = res.data.total;
						_this.page++;
					}
					
				})
			},
			//确认农机手接单
			// sure(id,work_status){
			// 	var _this = this;
			// 	_this.$http('apply.nh_sure_njs',{
			// 		work_id:id,
			// 		work_status:work_status,
			// 	}).then(res=>{
			// 		if(res.code == 1){
			// 			uni.showToast({
			// 				title:'操作成功',
			// 				icon:'none',
			// 				success(){
			// 					_this.xuqiuList = [];
			// 					_this.page =1;
			// 					_this.getXuqiuList(1);
			// 				}
			// 			})
			// 		}else{
			// 			uni.showToast({
			// 				title:res.msg,
			// 				icon:'none',
			// 			})
			// 		}
			// 	})
			// },
			//确认已支付定金
			sureDing(id){
				uni.navigateTo({
					url:'/pages/index/payDing?id='+id,
				})
			},
			//验收
			yanshou(id,work_status){
				var _this = this;
				_this.$http('apply.nh_yanshou',{
					work_id:id,
					work_status:work_status,
				}).then(res=>{
					if(res.code == 1){
						uni.showToast({
							title:'操作成功',
							icon:'none',
							success(){
								_this.xuqiuList = [];
								_this.page =1;
								_this.getXuqiuList(1);
							}
						})
					}else{
						uni.showToast({
							title:res.msg,
							icon:'none',
						})
					}
				})
			},
			
			goUrl(url){
				uni.navigateTo({
					url:url
				})
			},
			call(mobile) {
				uni.makePhoneCall({
					phoneNumber: mobile
				})
			}
		}
	}
</script>

<style>
	.u-card-wrap { 
		padding: 1px;
	}
	.u-body-item {
		font-size: 32rpx;
		color: #333;
		padding: 20rpx 10rpx;
	}	
	.u-body-item image {
		width: 120rpx;
		flex: 0 0 120rpx;
		height: 120rpx;
		border-radius: 8rpx;
		margin-left: 12rpx;
	}
	.btn{
		width: 100rpx;
		height: 100rpx;
		background-color: rgb(75, 187, 137);
		color: #fff;
		text-align: center;
		line-height: 100rpx;
		font-size: 30rpx;
		padding: 0;
		border-radius: 50rpx;
		position: fixed;
		bottom: 110rpx;
		right: 30rpx;
	}
	.titlee{
		width: 150rpx;
		display: inline-block;
		text-align: justify;
		font-weight: bold;
		text-align-last:justify;
	}
	.card_view view{
		margin: 10rpx 0;
	}
	.btn1{
			background-color: #4bbb89;
			color: #fff;
		}
</style>
